package mk.com.it.android;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * @author ristes
 * 
 */
public class DefaultArrayAdapter extends ArrayAdapter<RssPost> {
	
	private LayoutInflater vi;

	public DefaultArrayAdapter(Context context, int textViewResourceId,
			List<RssPost> objects, LayoutInflater li) {
		super(context, textViewResourceId, objects);
		this.vi=li;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View v = convertView;
		if (v == null) {			
			v = vi.inflate(R.layout.post_list_item, null);
		}

		RssPost post = super.getItem(position);
		String titleString = post.getTitle();
		String linkString = post.getLink().toString();
		String dateString = post.getPubDate();
		StringBuilder sb = new StringBuilder(titleString);
		sb.append("\n");
		sb.append(linkString);
		sb.append("\n");
		sb.append(dateString);

		ImageView postImageView = (ImageView) v
				.findViewById(R.id.postItemImage);

		postImageView.setImageDrawable(postImageView.getResources()
				.getDrawable(R.drawable.icon));

		TextView postTextView = (TextView) v.findViewById(R.id.postItemText);
		postTextView.setText(sb.toString());

		return v;

	}

}
